var _winDefaultLoad = null;
var _timerUserStatus = null;

var _winSelectPerson = null;
var _inputPersonCallBack = null;
var _inputPersonObj = null;

var _winSelectItem = null;
var _inputItemCallBack = null;
var _inputItemObj = null;
var _isTestVersion = false;

var _commonServerUrl = "http://common.zyctd.net";


Namespace = new Object();

Namespace.register = function (fullName) {

    var arrayFullName = fullName.split('.');
    var objStr = "";
    var evalStr = "";

    for (var i = 0; i < arrayFullName.length; i++) {

        if (i >= 1) {
            objStr += ".";
        }

        objStr += arrayFullName[i];

        evalStr += "if (typeof(" + objStr + ") == 'undefined') { " + objStr + " = new Object();} ";
    }

    if (evalStr != "") {
        eval(evalStr);
    }
}

Namespace.register("WebTool.CommonJs.Tool");


var PageHander = function () {

    this.PageNo = 1;
    this.PageSize = 10;
    this.PageCount = 1;
    this.RowCount = 1;
    this.HolderId = null;
    this.CallBack = null;
    this.HanderName = null;
    this.IsShowFloor = true;
    this.ParamObj = {};

    this.ShowPage = function (handerName, holderId, callBack, rowCount, paramObj) {
        this.HanderName = handerName;
        this.HolderId = holderId;
        this.CallBack = callBack;
        this.RowCount = rowCount;
        this.ParamObj = paramObj;

        this.AllPageCount();

        var pageStr = this.GetPageStr();

        if (this.PageCount <= 0)
        {
            pageStr = "";
        }

        $("#" + this.HolderId + "").html(pageStr);
    }

    this.GetCommonStr = function (min, max) {
        var htmlStr = "";

        for (var i = min; i <= max; i++) {
            if (this.PageNo != i) {
                htmlStr += " <a href='javascript:void(0)' onclick='" + this.HanderName + ".Floor_Click(" + i + ")' style=\"float: left; padding:3px 9px 3px 9px;line-height:20px;font-size:12px; margin-left: 4px; border: 1px solid #E0E7ED; border-radius:5px; text-decoration: none;\"  >" + i + "</a> ";
            } else {
                htmlStr += " <strong style=\"float: left;height:24px; padding:3px 9px 3px 9px; line-height:20px;font-size:12px;margin-left: 4px;color:#FF7510 \" >" + i + "</strong> ";
            }
        }

        return htmlStr;
    }

    this.GetPointStr = function () {
        var htmlStr = " <a  style=\"float: left; padding:3px 9px 3px 9px;line-height:20px; margin-left: 4px; border: 1px solid #E0E7ED;border-radius:5px; text-decoration: none; \" >...</a>";
        return htmlStr;
    }

    this.GetNumberStr = function () {
        var htmlStr = "";

        //如果总页数<=7
        //循环7个方块
        if (this.PageCount <= 7) {
            htmlStr += this.GetCommonStr(1, this.PageCount);
            return htmlStr;
        }

        //如果总页数>7

        //如果当前页<=5则，循环1-6加...
        if (this.PageNo <= 5) {
            htmlStr += this.GetCommonStr(1, 6);

            htmlStr += this.GetPointStr();//...

            return htmlStr;
        }

        //如果当前页>=6
        //如果当前页在最后3页中则显示12...加最后4个
        if (this.PageNo >= (this.PageCount - 2)) {

            htmlStr += this.GetCommonStr(1, 2);
            htmlStr += this.GetPointStr();//...

            //最后4个
            htmlStr += this.GetCommonStr((this.PageCount - 3), this.PageCount);

            return htmlStr;
        } else {
            //如果当前页>=6且不在最后3页中则显示12...xyz...
            htmlStr += this.GetCommonStr(1, 2);
            htmlStr += this.GetPointStr();//...

            htmlStr += this.GetCommonStr(this.PageNo - 1, this.PageNo + 1);

            htmlStr += this.GetPointStr();//...

            return htmlStr;
        }
    }

    this.GetPageStr = function () {
        var pageStr = "<div style='line-height:26px;display:inline-block'>";

        //上一页
        if (this.PageNo != 1) {
            pageStr += "<a href='javascript:void(0)'  style=\"float: left; padding:3px 9px 3px 9px;line-height:20px;font-size:12px; margin-left: 4px; border: 1px solid #E0E7ED; border-radius:5px; \"  onclick='" + this.HanderName + ".PrevPage_Click()' >上一页</a>";
        } else {
            pageStr += "<a href='javascript:void(0)'  style=\"float: left; padding:3px 9px 3px 9px;line-height:20px;font-size:12px; margin-left: 4px; border: 1px solid #E0E7ED; border-radius:5px; color:#999999;text-decoration: none;cursor:default; \"  >上一页</a>";
        }

        //数码页
        pageStr += this.GetNumberStr();

        //下一页
        if (this.PageNo != this.PageCount) {
            pageStr += " <a href='javascript:void(0)'  style=\"float: left; padding:3px 9px 3px 9px;line-height:20px; font-size:12px;margin-left: 4px; border: 1px solid #E0E7ED;  border-radius:5px; \"  onclick='" + this.HanderName + ".NextPage_Click()'>下一页</a>";
        } else {
            pageStr += " <a href='javascript:void(0)'  style=\"float: left; padding:3px 9px 3px 9px;line-height:20px; font-size:12px;margin-left: 4px; border: 1px solid #E0E7ED;  border-radius:5px; color:#999999;text-decoration: none;cursor:default;  \" >下一页</a>";
        }

        pageStr += " <label style='float: left; font-size:12px;height 26px; padding 0px 8px; margin-left 4px; border 1px solid #e0e7ed; '>&nbsp;共" + this.PageCount + "页&nbsp;</label> ";

        if (this.IsShowFloor) {
            pageStr += "  <label style='float: left; height 26px;font-size:12px; padding 0px 8px; margin-left 4px; border 1px solid #e0e7ed; '>到第</label><input type='text' id='" + this.HolderId + "Floor' style='width:20px;height:24px;font-size:12px;float:left;border:1px solid #E0E7ED;border-radius:5px;' onkeyup='" + this.HanderName + ".MyKeyUp(this)'  onafterpaste='" + this.HanderName + ".MyKeyUp(this)'   /> <label style='float: left; height 26px;font-size:12px; padding 0px 8px; margin-left 4px; border 1px solid #e0e7ed; '>页&nbsp;</label>";
            pageStr += " <a href='javascript:void(0)' onclick='" + this.HanderName + ".Floor_To()'  style=\"float: left; padding:3px 9px 3px 9px;line-height:20px;font-size:12px; margin-left: 4px; border: 1px solid #E0E7ED;border-radius:5px;  \" >确定</a>";
        }

        pageStr += "</div>";
        return pageStr;
    }

    this.PrevPage_Click = function () {
        this.PageNo -= 1;
        this.GetPageData();
    }

    this.NextPage_Click = function () {
        this.PageNo += 1;
        this.GetPageData();
    }

    this.Floor_Click = function (pageNo) {
        this.PageNo = pageNo;
        this.GetPageData();
    }

    this.Floor_To = function () {
        this.PageNo = parseInt($("#" + this.HolderId + "Floor").val());
        this.GetPageData();
    }

    this.GetPageData = function () {

        if (isNaN(this.PageNo) || this.PageNo < 1) {
            this.PageNo = 1;
        }

        if (this.PageNo > this.PageCount) {
            this.PageNo = this.PageCount;
        }


        this.CallBack(this.ParamObj);
    }

    this.AllPageCount = function () {

        this.PageCount = parseInt(this.RowCount / this.PageSize);

        if (this.RowCount % this.PageSize > 0) {
            this.PageCount++;
        }
    }

    this.MyKeyUp = function (obj) {
        var inputStr = $(obj).val();
        inputStr = inputStr.replace(/\D/g, '');
        $(obj).val(inputStr);

        if (event.keyCode == 13) {
            this.Floor_To();
        }
    }

}

//查找指定参数对象
function QueryKey(key) {

    var searchStr = location.search.slice(1);
    var arrayPara = searchStr.split("&");

    for (var i = 0; i < arrayPara.length; i++) {
        var paraObj = GetParaJsonObj(arrayPara[i]);

        if (paraObj.key == key) {

            return paraObj.value;
        }
    }

    return null;
}


function ChangeKey(key,value) {

    var oldValue = QueryKey(key);

    if (oldValue != null)
    {
        var oldObj = key + "=" + oldValue;
        var newObj = key + "=" + value;
        var History = window.history;
        var newUrl = window.location.href.replace(oldObj, newObj);
        History.pushState({}, "", newUrl);
        
       
    }
}



//参数字符转换为json对象
function GetParaJsonObj(paraStr) {
    var paraObj = {}

    var arrObj = paraStr.split("=");

    paraObj.key = arrObj[0];
    paraObj.value = arrObj[1];

    return paraObj;
}

function QueryKeyForHtml(index) {

    var searchStr = location.pathname;
    searchStr = searchStr.substring(1);
    var arrayPara = searchStr.split("-");

    var result = arrayPara[index];
    
    if (result != undefined && result != null)
    {
        return result;
    }

    return null;
}

//获取价格mbid
function QueryKeyForPrice() {

    var addr = GetUrlRelativePath();
    var lastIndex = addr.lastIndexOf("/");
    addr = addr.substring(lastIndex + 3);
    addr = addr.split(".")[0];

    var mbid = parseInt(addr);
    return mbid;
}

//轮询
$(document).ready(function () {
    //setInterval("VisitServer()", 1000 * 60 * 5);
});

function VisitServer() {

    $.ajax({
        url: "/api/Home/GetOnlineUserInfo",
        type: "post",
        data: {},
        success: function (ret) {


        }
    });


}

//编辑器是否为空
function EditKindIsNull(kindObj) {
    kindObj.sync();
    var inputStr = kindObj.options.srcElement.value;
    inputStr = RemoveHTMLTag(inputStr);

    if (inputStr == "") {
        return true;
    } else {
        return false;
    }

}

//获取编辑器内容
function GetKindContent(kindObj) {
    var kindContent = "";

    if (kindObj.isEmpty()) {
        kindContent = "";
    } else {
        kindContent = kindObj.html();
        kindContent = MyHtmlEncod(kindContent);
    }

    return kindContent;
}






//多个参数转换为Json对象
WebTool.CommonJs.Tool.GetSendStr = function (obj) {

    var sendStr = "";

    if (obj != undefined) {


        var paraCount = 0;

        for (para in obj) {
            paraCount++;
        }

        var i = 0;

        for (itemName in obj) {

            if (i >= 1 && i < paraCount) {
                sendStr += "&";
            }

            sendStr += itemName + "=" + WebTool.CommonJs.Tool.ObjToJson(obj[itemName]);

            i++;
        }

    }

    return sendStr;

}

//值对象转换为Json对象
WebTool.CommonJs.Tool.ObjToJson = function (obj) {

    //如果空则返回空
    if (obj == null) {
        return null;
    }

    var retObj = [];

    //如果对象是字符类型
    if (typeof obj == "string") {
        return "\"" + obj.replace(/([\'\"\\])/g, "\\$1").replace(/(\n)/g, "\\n").replace(/(\r)/g, "\\r").replace(/(\t)/g, "\\t") + "\"";
        //return obj;
    }

    //如果对象是对象类型
    if (typeof obj == "object") {

        //如果对象是单个对象
        if (!obj.sort) {

            for (var i in obj) {
                if (typeof obj[i] != "function") {
                    var item = "\"" + i + "\":" + WebTool.CommonJs.Tool.ObjToJson(obj[i]);
                    retObj.push(item);
                }
            }

            retObj = "{" + retObj.join() + "}";
            //如果对象是数组
        } else {
            for (var i = 0; i < obj.length; i++) {
                if (typeof obj[i] != "function") {
                    retObj.push(WebTool.CommonJs.Tool.ObjToJson(obj[i]))
                }
            }

            retObj = "[" + retObj.join() + "]"
        }

        return retObj;
    }

    //如果对象是布尔类型
    if (typeof obj == "boolean") {
        return "\"" + obj.toString() + "\"";
    }
    else {                      //如果对象是其他类型
        return obj.toString();
    }

}



var Base64_Self =
{
    /**
     * 此变量为编码的key，每个字符的下标相对应于它所代表的编码。
     */
    enKey: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/',
    /**
     * 此变量为解码的key，是一个数组，BASE64的字符的ASCII值做下标，所对应的就是该字符所代表的编码值。
     */
    deKey: new Array(
        -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
        -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
        -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, -1, -1, 63,
        52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -1, -1, -1,
        -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
        15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1,
        -1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
        41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -1, -1, -1, -1, -1
    ),
    /**
     * 编码
     */
    encode: function (src) {
        //用一个数组来存放编码后的字符，效率比用字符串相加高很多。
        var str = new Array();
        var ch1, ch2, ch3;
        var pos = 0;
        //每三个字符进行编码。
        while (pos + 3 <= src.length) {
            ch1 = src.charCodeAt(pos++);
            ch2 = src.charCodeAt(pos++);
            ch3 = src.charCodeAt(pos++);
            str.push(this.enKey.charAt(ch1 >> 2), this.enKey.charAt(((ch1 << 4) + (ch2 >> 4)) & 0x3f));
            str.push(this.enKey.charAt(((ch2 << 2) + (ch3 >> 6)) & 0x3f), this.enKey.charAt(ch3 & 0x3f));
        }
        //给剩下的字符进行编码。
        if (pos < src.length) {
            ch1 = src.charCodeAt(pos++);
            str.push(this.enKey.charAt(ch1 >> 2));
            if (pos < src.length) {
                ch2 = src.charCodeAt(pos);
                str.push(this.enKey.charAt(((ch1 << 4) + (ch2 >> 4)) & 0x3f));
                str.push(this.enKey.charAt(ch2 << 2 & 0x3f), '=');
            } else {
                str.push(this.enKey.charAt(ch1 << 4 & 0x3f), '==');
            }
        }
        //组合各编码后的字符，连成一个字符串。
        return FilterSpecialChars(str.join(''));
    },

    /**
     * 解码。
     */
    decode: function (src) {
        //用一个数组来存放解码后的字符。
        var str = new Array();
        var ch1, ch2, ch3, ch4;
        var pos = 0;
        //过滤非法字符，并去掉'='。
        src = src.replace(/[^A-Za-z0-9\+\/]/g, '');
        //decode the source string in partition of per four characters.
        while (pos + 4 <= src.length) {
            ch1 = this.deKey[src.charCodeAt(pos++)];
            ch2 = this.deKey[src.charCodeAt(pos++)];
            ch3 = this.deKey[src.charCodeAt(pos++)];
            ch4 = this.deKey[src.charCodeAt(pos++)];
            str.push(String.fromCharCode(
                (ch1 << 2 & 0xff) + (ch2 >> 4), (ch2 << 4 & 0xff) + (ch3 >> 2), (ch3 << 6 & 0xff) + ch4));
        }
        //给剩下的字符进行解码。
        if (pos + 1 < src.length) {
            ch1 = this.deKey[src.charCodeAt(pos++)];
            ch2 = this.deKey[src.charCodeAt(pos++)];
            if (pos < src.length) {
                ch3 = this.deKey[src.charCodeAt(pos)];
                str.push(String.fromCharCode((ch1 << 2 & 0xff) + (ch2 >> 4), (ch2 << 4 & 0xff) + (ch3 >> 2)));
            } else {
                str.push(String.fromCharCode((ch1 << 2 & 0xff) + (ch2 >> 4)));
            }
        }
        //组合各解码后的字符，连成一个字符串。
        return str.join('');
    }

};

//过滤特殊字符
function FilterSpecialChars(str) {
    str = str.replace(/\+/g, "%2B");
    str = str.replace(/\&/g, "%26");
    return str;
}

//验证是否为中文
function IsChinese() {
    var reg = /^[\u4E00-\u9FA5]+$/;

    if (!reg.test(str)) {
        return false;
    } else {
        return true;
    }


}


//验证guid
function CheckGuid(guidStr) {
    var regular = /^[0-9a-fA-F]{8}(-[0-9a-fA-F]{4}){3}-[0-9a-fA-F]{12}$/;
    var ret = guidStr.match(regular);

    if (ret == null) {
        return false;
    } else {
        return true;
    }
}

//过滤html标签
function RemoveHTMLTag(str) {

    str = str.replace(/<\/?(?!img|embed)[^>]*>/gi, "");   //去除HTML 除img和embed
    str = str.replace(/\s*/g, "");          //去除等价于 [\f\n\r\t\v]
    str = str.replace(/&nbsp;/ig, '');         //去掉&nbsp;
    return str;

}

//添加cookie分钟
function SetCookieForMin(cooName, value, keepMin) {

    var expiresDate = new Date();
    expiresDate.setTime(expiresDate.getTime()+ 8*60*60*1000 + keepMin*60*1000);

    var cooValue = (cooName + "=" + escape(value));
    cooValue +=(";expires=" + expiresDate.toGMTString());
    cooValue += ";path=/";

    document.cookie = cooValue;
}

//添加cookie天数
function SetCookieForDay(cooName, value, keepDay,doMain) {
    var expiresDate = new Date();
    expiresDate.setTime(expiresDate.getTime()+ 8*60*60*1000 + keepDay*24*60*60*1000);

    var cooValue = (cooName + "=" + escape(value));
    cooValue +=(";expires=" + expiresDate.toGMTString());
    cooValue += ";path=/";

    if (doMain != undefined && doMain != null && doMain != "")
    {
        cooValue += ";domain=" + doMain;
    }

    document.cookie = cooValue;
}

//获取cookie
function GetCookie(cooName) {

    var arr = document.cookie.match(new RegExp("(^|)" + cooName + "=([^;]*)(;|$)"));

    if (arr != null)
    {
        return unescape(arr[2]);
    }

    return "";

    //if (document.cookie.length > 0) {
    //    cooBegin = document.cookie.indexOf(cooName + "=")

    //    if (cooBegin != -1) {
    //        cooBegin = cooBegin + cooName.length + 1
    //        cooEnd = document.cookie.indexOf(";", cooBegin)

    //        if (cooEnd == -1) {
    //            cooEnd = document.cookie.length
    //        }

    //        return unescape(document.cookie.substring(cooBegin, cooEnd))
    //    }
    //}

    
}

// 清除 Cookie 
function DelCookie(cooName) {
    
    var expiresDate = new Date();
    expiresDate.setTime(expiresDate.getTime() - 1 * 24 * 60 * 60 * 1000);

    var cooValue = (cooName + "=0");
    cooValue += (";expires=" + expiresDate.toGMTString());
    cooValue += ";path=/";

    document.cookie = cooValue;

}

//是否有img标签
function IsHaveImgTag(str) {
    var reg = /<\/?(img|embed)[^>]*>/gi;

    if (!reg.test(str)) {
        return false;
    } else {
        return true;
    }

}

//是否有embed标签
function IsHaveEmbedTag(str) {
    var reg = /<\/?(img|embed)[^>]*>/gi;

    if (!reg.test(str)) {
        return false;
    } else {
        return true;
    }

}

//获取浏览器类型
function GetExplorerName() {

    var explorer = window.navigator.userAgent;

    if (explorer.indexOf("MSIE") >= 0) {//IE
        return "MSIE";
    }
    else if (explorer.indexOf("Firefox") >= 0) {//Firefox
        return "Firefox";
    }
    else if (explorer.indexOf("Chrome") >= 0) {//Chrome
        return "Chrome";
    }
    else if (explorer.indexOf("Opera") >= 0) {//Opera
        return "Opera";
    }
    else if (explorer.indexOf("Safari") >= 0) {//Safari
        return "Safari";
    }

}

//获取浏览器版本号
function GetExplorerVersion() {
    var explorerName = GetExplorerName();

    if (explorerName == "MSIE") {//IE

        var versionName = navigator.appVersion.split(";");
        versionName = versionName[1].split(" ");
        versionName = versionName[2];
        versionName = versionName.split(".");
        versionName = versionName[0];

        var versionNo = parseInt(versionName);

        if (versionNo < 8) {

            alert("请使用IE7以上浏览器或者谷歌浏览器！");
            return false;
        }
    }
    else if (explorerName == "Firefox") {//Firefox

    }
    else if (explorerName == "Chrome") {//Chrome

    }
    else if (explorerName == "Opera") {//Opera

    }
    else if (explorerName == "Safari") {//Safari

    }

    return true;

}


//html字符编码
function MyHtmlEncod(str) {
    str = str.replace(/&/g, '&amp;');       //&
    str = str.replace(/ /g, '&nbsp;');      //空格

    str = str.replace(/</g, '&lt;');        //<
    str = str.replace(/>/g, '&gt;');        //>

    str = str.replace(/\&/g, "%26");
    str = str.replace(/\+/g, "%2B");

    //str = str.replace(/x22/g, '&quot;');    //"
    //str = str.replace(/x27/g, '&#39;');     //'

    return str;
}

//html字符解码
function MyHtmlDecode(str) {
    str = str.replace(/&amp;/gi, '&');
    str = str.replace(/&nbsp;/gi, ' ');

    str = str.replace(/&lt;/gi, '<');
    str = str.replace(/&gt;/gi, '>');

    //str = str.replace(/&quot;/gi, '\"');
    //str = str.replace(/&#39;/gi, '\'');

    return str;
}


function PopInfo(infoStr)
{
   
    $.layer({
        type: 0,
        shade: [0.5, '#fff'],
        area: ['auto', 'auto'],
        dialog: {
            type: 1,
            msg: infoStr

        }
    });

}

function ShowLoading()
{

    _winDefaultLoad = layer.load(0, 2);


}

function HideLoading(loadObj)
{
    if (_winDefaultLoad != null)
    { 
        layer.close(_winDefaultLoad);
    }
}


//表格定义
var GridDeal = function (){
    //#region 系统属性
    this.autoRowHeight = false;//根据该行的内容定义设置行的高度。设置为false可以提高负载性能。
    this.columns = undefined;//[[{},{}...]]，列配置对象
    this.ctrlSelect = false;//在启用多行选择的时候允许使用Ctrl键+鼠标点击的方式进行多选操作
    this.checkOnSelect = true;//如果为true，当用户点击行的时候该复选框就会被选中或取消选中。如果为false，当用户仅在点击该复选框的时候才会被选中或取消。
    this.data = null;//[{},{}]表格数据
    //this.editors= null;//object,在编辑行的时候使用的编辑器
    this.fit = true;//表格自动适应页面宽度
    this.fitColumns = true;//真正的自动展开/收缩列的大小，以适应网格的宽度，防止水平滚动。
    this.frozenColumns = [[]];// [[]]这些列将会被冻结在左侧
    this.height = 495;//660默认表格高度,337为刚好10行。500为一屏幕
    //this.loader= function () { };//定义如何从远程服务器加载数据。返回false可以放弃本次请求动作。该函数接受以下参数：param：参数对象传递给远程服务器。success(data)：当检索数据成功的时候会调用该回调函数。error()：当检索数据失败的时候会调用该回调函数。
    //this.loadFilter= function () { };//返回过滤数据显示。该函数带一个参数'data'用来指向源数据（即：获取的数据源，比如Json对象）。您可以改变源数据的标准数据格式。这个函数必须返回包含'total'和'rows'属性的标准数据对象    
    this.loadMsg = "加载中......";//在从远程站点加载数据的时候显示提示消息
    this.method = "post";//该方法类型请求远程数据
    this.multiSort = false;//定义是否允许多列排序
    this.nowrap = true;//如果为true，则在同一行中显示数据。设置为true可以提高加载性能
    this.pagination = true;//如果为true，则在DataGrid控件底部显示分页工具栏
    this.pagePosition = "bottom";//定义分页工具栏的位置。可用的值有：'top','bottom','both'
    this.pageNumber = 1;//初始化页码
    this.pageSize = 15;//初始化页面大小
    this.pageList = [10, 15, 20, 30, 40, 50],//初始化页面大小选择列表
    this.queryParams = {};//在请求远程数据的时候发送额外的参数
    this.rownumbers = true;//如果为true，则显示一个行号列
    this.resizeHandle = "right";//调整列的位置，可用的值有：'left','right','both'。在使用'right'的时候用户可以通过拖动右侧边缘的列标题调整列，等等
    this.remoteSort = true;//定义从服务器对数据进行排序
    this.rowStyler = null;//定义行的样式
    this.striped = true;//是否显示斑马线效果
    this.singleSelect = true;//如果为true，则只允许选择一行
    this.selectOnCheck = true;//如果为true，单击复选框将永远选择行。 如果为false，选择行将不选中复选框
    this.sortName = null;//定义哪些列可以进行排序
    this.sortOrder = "asc";//定义列的排序顺序，只能是'asc'或'desc'
    this.showHeader = true;//是否显示行头
    this.showFooter = false;//是否显示行脚
    this.scrollbarSize = 18;//滚动条的宽度(当滚动条是垂直的时候)或高度(当滚动条是水平的时候)
    this.title = null;//表格标题
    this.toolbar = null;//对象，顶部工具栏的DataGrid面板
    this.url = null;//一个URL从远程站点请求数据
    //this.view= null;//object,DataGrid的视图
    this.width = undefined;//表格宽度,默认自动填充满
    //#endregion

    //#region 自定义属性
    this.gridId = null;//表格Id
    //#endregion

    //绑定表格
    this.bindGrid= function () {

        if (this.gridId == null) {
            alert("请传入表格Id");
            return;
        }

        this.queryParams.MyToken = top._myToken;

        var gridObj = $('#' + this.gridId);

        gridObj.datagrid({
            //属性
            autoRowHeight: this.autoRowHeight,//根据该行的内容定义设置行的高度。设置为false可以提高负载性能。
            columns: this.columns,//[[{},{}...]]，列配置对象
            ctrlSelect: this.ctrlSelect,//在启用多行选择的时候允许使用Ctrl键+鼠标点击的方式进行多选操作
            checkOnSelect: this.checkOnSelect,//如果为true，当用户点击行的时候该复选框就会被选中或取消选中。如果为false，当用户仅在点击该复选框的时候才会被选中或取消。
            data: this.data,//[{},{}]表格数据
            //editors: this.editors,//object,在编辑行的时候使用的编辑器
            fitColumns: this.fitColumns,//真正的自动展开/收缩列的大小，以适应网格的宽度，防止水平滚动。
            frozenColumns: this.frozenColumns,// [[]]这些列将会被冻结在左侧
            //fit:true,//自动适应页面宽度但在div中显示不了,去掉width也可以自动适应页面宽度，且在div中也可以正常显示
            height: this.height,//表格高度
            //loader: this.loader,//定义如何从远程服务器加载数据。返回false可以放弃本次请求动作。该函数接受以下参数：param：参数对象传递给远程服务器。success(data)：当检索数据成功的时候会调用该回调函数。error()：当检索数据失败的时候会调用该回调函数。
            //loadFilter: this.loadFilter,//返回过滤数据显示。该函数带一个参数'data'用来指向源数据（即：获取的数据源，比如Json对象）。您可以改变源数据的标准数据格式。这个函数必须返回包含'total'和'rows'属性的标准数据对象    
            loadMsg: this.loadMsg,//在从远程站点加载数据的时候显示提示消息
            method: this.method,//该方法类型请求远程数据
            multiSort: this.multiSort,//定义是否允许多列排序
            nowrap: this.nowrap,//如果为true，则在同一行中显示数据。设置为true可以提高加载性能
            pagination: this.pagination,//如果为true，则在DataGrid控件底部显示分页工具栏
            pagePosition: this.pagePosition,//定义分页工具栏的位置。可用的值有：'top','bottom','both'
            pageNumber: this.pageNumber,//初始化页码
            pageSize: this.pageSize,//初始化页面大小
            pageList: this.pageList,//初始化页面大小选择列表
            queryParams: this.queryParams,//在请求远程数据的时候发送额外的参数
            rownumbers: this.rownumbers,//如果为true，则显示一个行号列
            resizeHandle: this.resizeHandle,//调整列的位置，可用的值有：'left','right','both'。在使用'right'的时候用户可以通过拖动右侧边缘的列标题调整列，等等
            remoteSort: this.remoteSort,//定义从服务器对数据进行排序
            rowStyler: this.rowStyler,
            striped: this.striped,//是否显示斑马线效果
            singleSelect: this.singleSelect,//如果为true，则只允许选择一行
            selectOnCheck: this.selectOnCheck,//如果为true，单击复选框将永远选择行。 如果为false，选择行将不选中复选框
            sortName: this.sortName,//定义哪些列可以进行排序
            sortOrder: this.sortOrder,//定义列的排序顺序，只能是'asc'或'desc'
            showHeader: this.showHeader,//是否显示行头
            showFooter: this.showFooter,//是否显示行脚
            scrollbarSize: this.scrollbarSize,//滚动条的宽度(当滚动条是垂直的时候)或高度(当滚动条是水平的时候)
            title: this.title ,//表格标题
            toolbar: this.toolbar,//对象，顶部工具栏的DataGrid面板
            url: this.url,//一个URL从远程站点请求数据
            // view: this.view,//object,DataGrid的视图
             width: this.width,
            //方法
            onLoadSuccess: this.onLoadSuccess,
            onLoadError: this.onLoadError,
            onBeforeLoad: this.onBeforeLoad,
            onClickRow: this.onClickRow,
            onDblClickRow: this.onDblClickRow,
            onClickCell: this.onClickCell,
            onDblClickCell: this.onDblClickCell,
            onSortColumn: this.onSortColumn,
            onResizeColumn: this.onResizeColumn,
            onSelect: this.onSelect,
            onUnselect: this.onUnselect,
            onSelectAll: this.onSelectAll,
            onUnselectAll: this.onUnselectAll,
            onCheck: this.onCheck,
            onUncheck: this.onUncheck,
            onCheckAll: this.onCheckAll,
            onUncheckAll: this.onUncheckAll,
            onBeforeEdit: this.onBeforeEdit,
            onAfterEdit: this.onAfterEdit,
            onCancelEdit: this.onCancelEdit,
            onHeaderContextMenu: this.onHeaderContextMenu,
            onRowContextMenu: this.onRowContextMenu,
        });

        return gridObj;
    };

    //#region 系统方法
    //在数据加载成功的时候触发,data返回的数据
    this.onLoadSuccess = function (data) {
 
    };

    //在载入远程数据产生错误的时候触发,error对象
    this.onLoadError = function (error) {
        ErrorResultDeal(error.status, error.responseText);
    };

    //在载入请求数据数据之前触发，如果返回false可终止载入数据操作
    this.onBeforeLoad = function (param) {       
        return true;
    };

    //在用户点击一行的时候触发 : rowIndex：点击的行的索引值，该索引值从0开始。rowData：对应于点击行的记录。
    this.onClickRow = function (rowIndex, rowData) {

    };

    //在用户双击一行的时候触发：rowIndex：点击的行的索引值，该索引值从0开始。rowData：对应于点击行的记录。
    this.onDblClickRow = function (rowIndex, rowData) {

    };

    //在用户点击一个单元格的时候触发
    this.onClickCell = function (rowIndex, field, value) {

    };

    //在用户双击一个单元格的时候触发
    this.onDblClickCell = function (rowIndex, field, value) {

    };

    //在用户排序一列的时候触发,sort：排序列字段名称,order：排序列的顺序(ASC或DESC)
    this.onSortColumn = function (sort, order) {
    };

    //在用户调整列大小的时候触发
    this.onResizeColumn = function (field, width) {

    };

    //在用户选择一行的时候触发，rowIndex：选择的行的索引值，索引从0开始,rowData：对应于所选行的记录
    this.onSelect = function (rowIndex, rowData) {

    };

    //在用户取消选择一行的时候触发
    this.onUnselect = function (rowIndex, rowData) {

    },

    //在用户选择所有行的时候触发
    this.onSelectAll = function (rows) {

    };

    //在用户取消选择所有行的时候触发
    this.onUnselectAll = function (rows) {

    };

    //在用户勾选一行的时候触发
    this.onCheck = function (rowIndex, rowData) {

    };

    //在用户取消勾选一行的时候触发
    this.onUncheck = function (rowIndex, rowData) {

    };

    //在用户勾选所有行的时候触发
    this.onCheckAll = function (rows) {

    };

    //在用户取消勾选所有行的时候触发
    this.onUncheckAll = function (rows) {

    };

    //在用户开始编辑一行的时候触发
    this.onBeforeEdit = function (rowIndex, rowData) {

    };

    //在用户完成编辑一行的时候触发，参数包括：rowIndex：编辑行的索引，索引从0开始。rowData：对应于完成编辑的行的记录。changes：更改后的字段(键)/值对
    this.onAfterEdit = function (rowIndex, rowData, changes) {

    };

    //在用户取消编辑一行的时候触发
    this.onCancelEdit = function (rowIndex, rowData) {

    };

    //在鼠标右击DataGrid表格头的时候触发
    this.onHeaderContextMenu = function (e, field) {

    };

    //在鼠标右击一行记录的时候触发
    this.onRowContextMenu = function (e, rowIndex, rowData) {

    };
    //#endregion




}


function CheckLoginAndPower(ret)
{
    var dataType = typeof (ret);

    if (dataType == "string") {

       
        var jsonRet = eval('(' + ret + ')');

        if (jsonRet.Sign == 3) {
            alert(jsonRet.Msg);
            top.window.location.href = jsonRet.Url;
            return false;
        }
        else if (jsonRet.Sign == 4) {
            alert(jsonRet.Msg);
            return false;
        }

        return true;
    }

    return true;

}


//获取编辑器内容
function GetKindContent(kindObj) {
    var kindContent = "";

    if (kindObj.isEmpty()) {
        kindContent = "";
    } else {
        kindContent = kindObj.html();
        kindContent = MyHtmlEncod(kindContent);
    }

    return kindContent;
}


//html字符编码
function MyHtmlEncod(str) {
    str = str.replace(/&/g, '&amp;');       //&
    str = str.replace(/ /g, '&nbsp;');      //空格

    str = str.replace(/</g, '&lt;');        //<
    str = str.replace(/>/g, '&gt;');        //>

    str = str.replace(/\&/g, "%26");
    str = str.replace(/\+/g, "%2B");

    //str = str.replace(/x22/g, '&quot;');    //"
    //str = str.replace(/x27/g, '&#39;');     //'

    return str;
}

//html字符解码
function MyHtmlDecode(str) {
    str = str.replace(/&amp;/gi, '&');
    str = str.replace(/&nbsp;/gi, ' ');

    str = str.replace(/&lt;/gi, '<');
    str = str.replace(/&gt;/gi, '>');

    //str = str.replace(/&quot;/gi, '\"');
    //str = str.replace(/&#39;/gi, '\'');

    return str;
}


//编辑器是否为空
function EditKindIsNull(kindObj) {
    kindObj.sync();
    var inputStr = kindObj.options.srcElement.value;
    inputStr = RemoveHTMLTag(inputStr);

    if (inputStr == "") {
        return true;
    } else {
        return false;
    }

}

//上传附件
function UploadInit(uploadId, dealUrl, callFun) {

    var fileName = "";
    var resultInfo = null;
    
    $("#" + uploadId + "").uploadify({
        uploader: dealUrl,
        swf: "http://i"+ZYCLib.Domain+"/Scripts/PlugIn/uploadify3.2/uploadify.swf",
        buttonText: '上传',
        width: '60',
        height: '20',
        'queueID': 'uploadfileQueue',
        multi: false,
        queueSizeLimit: 1,
        fileTypeExts: '*.jpg;*.gif;*.jpeg;*.png;*.bmp',
        fileTypeDesc: '支持的格式：',
        fileSizeLimit: '50MB',
        method: 'post',
        removeCompleted: true,
        removeTimeout: 1,
        debug: false,
        auto: true,
        onSelectError: function (file, errorCode, errorMsg) {
            switch (errorCode) {
                case -100:
                    alert("上传的文件数量已经超出系统限制的" + $('#' + uploadId + '').uploadify('settings', 'queueSizeLimit') + "个文件！");
                    break;
                case -110:
                    alert("文件 [" + file.name + "] 大小超出系统限制的" + $('#' + uploadId + '').uploadify('settings', 'fileSizeLimit') + "大小！");
                    break;
                case -120:
                    alert("文件 [" + file.name + "] 大小异常！");
                    break;
                case -130:
                    alert("文件 [" + file.name + "] 类型不正确！");
                    break;
            }
        },
        onFallback: function () {
            alert("您未安装FLASH控件，无法上传图片！请安装FLASH控件后再试。");
        },
        onUploadSuccess: function (file, data, response) {
            //console.log("file:\n" + JSON.stringify(file));
            //console.log("data:\n" + data);
            //console.log("response:\n" + response);

            //if (data != null) {
            //    var retObj = eval("(" + data + ")");

            //    resultInfo += retObj.ID + ",";
            //}

            resultInfo = JSON.parse(data);
            fileName = file.name;

        },
        onUploadError: function (file, errorCode, errorMsg, errorString, swfuploadifyQueue) {
            var ret = 'id: ' + file.id
            + ' - 索引: ' + file.index
            + ' - 文件名: ' + file.name
            + ' - 文件大小: ' + file.size
            + ' - 类型: ' + file.type
            + ' - 创建日期: ' + file.creationdate
            + ' - 修改日期: ' + file.modificationdate
            + ' - 文件状态: ' + file.filestatus
            + ' - 错误代码: ' + errorCode
            + ' - 错误描述: ' + errorMsg
            + ' - 简要错误描述: ' + errorString;

            //console.log(ret);
            //alert(ret);
        },
        onUploadComplete: function (file, swfuploadifyQueue) {
            var ret = 'id: ' + file.id
            + ' - 索引: ' + file.index
            + ' - 文件名: ' + file.name
            + ' - 文件大小: ' + file.size
            + ' - 类型: ' + file.type
            + ' - 创建日期: ' + file.creationdate
            + ' - 修改日期: ' + file.modificationdate
            + ' - 文件状态: ' + file.filestatus
            ;

            //console.log(ret);
            //alert(ret);
        },
        onQueueComplete: function (queueData) {
            //console.log("queueData:\n" + JSON.stringify(queueData));

            //if (resultInfo != "") {
            //    alert(resultInfo);
            //} else {

            //alert(' 成功上传了' + queueData.uploadsSuccessful + '个');

            //}

            if (callFun != undefined && callFun != null) {
                //if (resultInfo != null) {
                //    resultInfo = resultInfo.substring(0, resultInfo.length - 1);
                //}
                //callFun(resultInfo);
                callFun(resultInfo, fileName);
            }

        },
        onUploadStart: function (file) {
            $("#" + uploadId + "").uploadify("settings", "formData", { 'MyToken': top._myToken });
        }


    });



}


function SendToServer(url, sendData, sendType, isAsync, isShowLoad, callback, isJsonp, newHost) {

    try {

        if (isShowLoad) {
            ShowLoading();
        }

        var ajaxObj = {};

        var defaultHost = "";

        if (isJsonp == false || isJsonp == undefined || isJsonp == null || isJsonp == "") {
            isJsonp = false;
        } else {
            isJsonp = true;
            defaultHost = _commonServerUrl;
        }
       
        if (newHost == undefined || newHost == null || newHost == "") {

        } else {

            defaultHost = newHost;
        }


        url = defaultHost + url;
        ajaxObj.url = url;
        sendData.MyToken = top._myToken;
        ajaxObj.data = sendData;
        ajaxObj.type = sendType;
        ajaxObj.async = isAsync;
     
        if (isJsonp) {
            ajaxObj.dataType = "jsonp";
            ajaxObj.jsonp = "callback";
        }

        ajaxObj.success = function (ret) {

            if (isShowLoad) {
                HideLoading();
            }

            if (typeof (callback) === "function") {
                callback(ret);
            }

        };

        ajaxObj.error = function (ret) {

            if (isShowLoad) {
                HideLoading();
            }

            ErrorResultDeal(ret.status, ret.responseText)
        };

        $.ajax(ajaxObj);

    } catch (e) {

        if (isShowLoad) {
            HideLoading();
        }

        if (_isTestVersion) {
            alert(e.name + ": " + e.message);
        }

    }

}

function InitGetPageInfo(pageCode) {

    SendToServer("/AdminSystem_Main/InitGetPageInfo", { pageCode: pageCode }, "get", false, true, function (ret) {

        if (ret != null) {
            for (var i in ret) {
                $("a[mytype='menuaction'][action='" + ret[i].ActionCode + "']").css("display", "inline");
                $("div[mytype='menuaction'][action='" + ret[i].ActionCode + "']").css("display", "block");
            }
        }

        $("a[mytype='menuaction']").each(function () {
            if ($(this).css("display") == "none") {
                $(this).remove();
            }
        });

        $("div[mytype='menuaction']").each(function () {
            if ($(this).css("display") == "none") {
                $(this).remove();
            }
        });

    })

}

//处理结果
function ErrorResultDeal(ret,msg)
{
    //console.log(msg);
    
    ret = ret.toString();

    switch (ret) {

        case "400":
        case "410":
            GameOver();
            alert("会话过期，请重新登陆系统");
            top.window.location = "/Admin/Home/Login.html";
            break;

        case "401":
        case "403":
            GameOver();
            alert("您没有权限");
            top.window.location = "/Admin/Home/Login.html";
            break;

        case "409":
            GameOver();
            alert("您已下线，您的账号已在别处登陆")
            top.window.location = "/Admin/Home/Login.html";
            break;

        default:
            var retMsg = msg;

            if (typeof (msg) === "object") {
                retMsg = JSON.stringify(ret);
            } 

            if (_isTestVersion) {
                alert(retMsg);
            }

            break;

    }

}

function BeginCheckUserStatus() {

    _timerUserStatus = setInterval(CheckUserStatus, 60000);
}

function EndCheckUserStatus() {
    if (_timerUserStatus != null)
    { 
        clearInterval(_timerUserStatus);
    }
}

function CheckUserStatus() {
    SendToServer("/AdminSystem_Main/CheckUserStatus", {}, "get", true, false, function (ret) {})
}

function GameOver()
{
    EndCheckUserStatus();
    top._myToken = "";
    DelCookie("cooMyToken");
}
 

function GetMyGuid() {
    var guid = "";
    for (var i = 1; i <= 32; i++) {
        var n = Math.floor(Math.random() * 16.0).toString(16);
        guid += n;
        if ((i == 8) || (i == 12) || (i == 16) || (i == 20))
            guid += "-";
    }
    return guid;
}


function InitInputChange(objId, callBack) {

    var element = document.getElementById(objId);

    if ("\v" == "v") {//IE
        element.onpropertychange = callBack;
    } else {//非IE
        element.addEventListener("input", callBack, false);
    }

}




//*********************************************************************选择用户

function SelectPerson(obj,typestr, callBack) {
    $(obj).attr("readonly", "readonly");

    CreateSelectPersonDiv();
    GetAllUserType();

    _inputPersonCallBack = callBack;
    _inputPersonObj = $(obj);

    _winSelectPerson = $.layer({
        type: 1,
        title: "选择用户",
        closebtn: true,
        border: [0],
        offset: ['100px', ''],
        area: ['456px', '443px'],
        page: { dom: '#divKaneSelectPerson' }
    });

    if (typestr == "localstaff")
    {
        GetLocalStaff();
    }
    else if (typestr == "localclient") {
        GetLocalClient
    }
    else {
        btnFindPersonClick();
    }

}

function CreateSelectPersonDiv() {
    var divHtml = "";

    //divHtml += " <div class='easyui-panel' id='divKaneSelectPerson' title='' style='padding: 5px 12px 0px 12px; width: 430px; height: 400px; border: 1px solid #ccc; display: none; '> ";

    divHtml += "    <table style='height:30px;'> ";
    divHtml += "        <tr> ";
    divHtml += "            <td>类型:</td> ";
    divHtml += "            <td><select style='height:22px;width:130px;' id='findPersonType' name='language'></select></td> ";
    divHtml += "            <td>姓名:</td> ";
    divHtml += "            <td><input style='height:18px;width:120px;' id='findPersonName' type='text' name='name' /></td> ";
    divHtml += "            <td><input type='button' value='搜索' onclick='btnFindPersonClick()' style='width: 80px; height: 24px; cursor: pointer' /></td> ";
    divHtml += "        </tr> ";
    divHtml += "    </table> ";

    divHtml += "    <div style='height:2px;'></div> ";

    divHtml += "    <table id='gridPersonInfo'></table> ";

    divHtml += "    <div style='height:4px;'></div> ";

    divHtml += "    <div style='text-align:center;padding:5px'> ";
    divHtml += "        <input type='button' value='确认' onclick='btnSavePersonClick()' style='width: 80px; height: 24px; cursor:pointer'  /> ";
    divHtml += "        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  ";
    divHtml += "        <input type='button' value='取消' onclick='btnCancelPersonClick()' style='width: 80px; height: 24px; cursor: pointer' /> ";
    divHtml += "    </div>  ";

    //divHtml += " </div>  ";


    $("#divKaneSelectPerson").remove();

    var divObj = document.createElement("div");
    divObj.setAttribute("id", "divKaneSelectPerson");
    divObj.setAttribute("class", "easyui-panel");
    divObj.setAttribute("title", "");
    divObj.setAttribute("style", "padding: 5px 12px 0px 12px; width: 430px; height: 400px; border: 1px solid #ccc; display: none;");
    divObj.innerHTML = divHtml;
    document.body.appendChild(divObj);


}

//获取本店员工
function GetLocalStaff() {
    var gridObj = new GridDeal();
    gridObj.gridId = "gridPersonInfo";
    gridObj.url = "/api/AdminSystem_Common/GetLocalStaff";
    gridObj.queryParams = { findPersonType: $("#findPersonType").val(), findPersonName: $("#findPersonName").val() };//
    gridObj.height = 315;
    gridObj.sortName = "UserType";
    gridObj.sortOrder = "asc";
    gridObj.idField = "Id";
    gridObj.pageSize = 10;
    gridObj.fitColumns = true;
    gridObj.columns = [[
        { field: 'UserTypeName', title: '用户类型名称', width: 150, sortable: true, align: 'center' },
        { field: 'UserName', title: '用户名称', width: 150, sortable: true, align: 'center' }

    ]];

    gridObj.bindGrid();
}
//获取本店会员
function GetLocalClient() {
    var gridObj = new GridDeal();
    gridObj.gridId = "gridPersonInfo";
    gridObj.url = "/api/AdminSystem_Common/GetLocalClient";
    gridObj.queryParams = { findPersonType: $("#findPersonType").val(), findPersonName: $("#findPersonName").val() };//
    gridObj.height = 315;
    gridObj.sortName = "UserType";
    gridObj.sortOrder = "asc";
    gridObj.idField = "Id";
    gridObj.pageSize = 10;
    gridObj.fitColumns = true;
    gridObj.columns = [[
        { field: 'UserTypeName', title: '用户类型名称', width: 150, sortable: true, align: 'center' },
        { field: 'UserName', title: '用户名称', width: 150, sortable: true, align: 'center' }

    ]];

    gridObj.bindGrid();
}

function GetAllUserType() {
    SendToServer("/AdminSystem_Common/GetAllUserType", {}, "get", false, false, function (ret) {

        var htmlStr = "<option value=\"0\" checked='checked' >--请选择--</option>";

        if (ret != null && ret != "") {
            for (var i in ret) {
                var obj = ret[i];
                htmlStr += "<option value=" + obj.TypeCode + ">" + obj.CodeName + "</option>";
            }
        }

        $("#findPersonType").html(htmlStr);

    })
}

function btnFindPersonClick() {

    var gridObj = new GridDeal();
    gridObj.gridId = "gridPersonInfo";
    gridObj.url = "/api/AdminSystem_Common/GetAllPerson";
    gridObj.queryParams = { findPersonType: $("#findPersonType").val(), findPersonName: $("#findPersonName").val() };//
    gridObj.height = 315;
    gridObj.sortName = "UserType";
    gridObj.sortOrder = "asc";
    gridObj.idField = "Id";
    gridObj.pageSize = 10;
    gridObj.fitColumns = true;
    gridObj.columns = [[
        { field: 'UserTypeName', title: '用户类型名称', width: 150, sortable: true, align: 'center' },
        { field: 'UserName', title: '用户名称', width: 150, sortable: true, align: 'center' }

    ]];

    gridObj.bindGrid();

}

function btnSavePersonClick() {

    var selRow = $("#gridPersonInfo").datagrid("getSelected");

    if (selRow == null) {

        $(_inputPersonObj).val("");

        $(_inputPersonObj).attr("UserId", "");
        $(_inputPersonObj).attr("UserType", "");
        $(_inputPersonObj).attr("UserTypeName", "");


    } else {

        $(_inputPersonObj).val(selRow.UserName);

        $(_inputPersonObj).attr("UserId", selRow.Id);
        $(_inputPersonObj).attr("UserType", selRow.UserType);
        $(_inputPersonObj).attr("UserTypeName", selRow.UserTypeName);

        if (_inputPersonCallBack != null && _inputPersonCallBack != undefined) {
            _inputPersonCallBack();
        }

    }


    btnCancelPersonClick();
}


function btnCancelPersonClick() {
    layer.close(_winSelectPerson);


}

//*************************************************************************************




//*********************************************************************选择项目

function SelectItem(obj, callBack) {
    $(obj).attr("readonly", "readonly");

    CreateSelectItemDiv();
    //GetAllItemType();

    _inputItemCallBack = callBack;
    _inputItemObj = $(obj);

    _winSelectItem = $.layer({
        type: 1,
        title: "选择项目",
        closebtn: true,
        border: [0],
        offset: ['100px', ''],
        area: ['456px', '443px'],
        page: { dom: '#divKaneSelectItem' }
    });

    btnFindItemClick();

}

function CreateSelectItemDiv() {
    var divHtml = "";

    //divHtml += " <div class='easyui-panel' id='divKaneSelectItem' title='' style='padding: 5px 12px 0px 12px; width: 430px; height: 400px; border: 1px solid #ccc; display: none; '> ";

    divHtml += "    <table style='height:30px;'> ";
    divHtml += "        <tr> ";
    //divHtml += "            <td>类型:</td> ";
    //divHtml += "            <td><select style='height:22px;width:130px;' id='findItemType' name='language'></select></td> ";
    divHtml += "            <td>名称:</td> ";
    divHtml += "            <td><input style='height:18px;width:120px;' id='findItemName' type='text' name='name' /></td> ";
    divHtml += "            <td><input type='button' value='搜索' onclick='btnFindItemClick()' style='width: 80px; height: 24px; cursor: pointer' /></td> ";
    divHtml += "        </tr> ";
    divHtml += "    </table> ";

    divHtml += "    <div style='height:2px;'></div> ";

    divHtml += "    <table id='gridItemInfo'></table> ";

    divHtml += "    <div style='height:4px;'></div> ";

    divHtml += "    <div style='text-align:center;padding:5px'> ";
    divHtml += "        <input type='button' value='确认' onclick='btnSaveItemClick()' style='width: 80px; height: 24px; cursor:pointer'  /> ";
    divHtml += "        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  ";
    divHtml += "        <input type='button' value='取消' onclick='btnCancelItemClick()' style='width: 80px; height: 24px; cursor: pointer' /> ";
    divHtml += "    </div>  ";

    //divHtml += " </div>  ";


    $("#divKaneSelectItem").remove();

    var divObj = document.createElement("div");
    divObj.setAttribute("id", "divKaneSelectItem");
    divObj.setAttribute("class", "easyui-panel");
    divObj.setAttribute("title", "");
    divObj.setAttribute("style", "padding: 5px 12px 0px 12px; width: 430px; height: 400px; border: 1px solid #ccc; display: none;");
    divObj.innerHTML = divHtml;
    document.body.appendChild(divObj);


}

//function GetAllItemType() {
//    SendToServer("/AdminSystem_Common/GetAllItemType", {}, "get", false, false, function (ret) {

//        var htmlStr = "<option value=\"0\" checked='checked' >--请选择--</option>";

//        if (ret != null && ret != "") {
//            for (var i in ret) {
//                var obj = ret[i];
//                htmlStr += "<option value=" + obj.TypeCode + ">" + obj.CodeName + "</option>";
//            }
//        }

//        $("#findItemType").html(htmlStr);

//    })
//}

function btnFindItemClick() {

    var gridObj = new GridDeal();
    gridObj.gridId = "gridItemInfo";
    gridObj.url = "/api/AdminSystem_Common/GetAllItem";
    gridObj.queryParams = { findItemName: $("#findItemName").val() };//
    gridObj.height = 315;
    gridObj.sortName = "ItemName";
    gridObj.sortOrder = "asc";
    gridObj.idField = "Id";
    gridObj.pageSize = 10;
    gridObj.fitColumns = true;
    gridObj.columns = [[

        { field: 'ItemName', title: '项目名称', width: 150, sortable: true, align: 'center' }

    ]];

    gridObj.bindGrid();

}

function btnSaveItemClick() {

    var selRow = $("#gridItemInfo").datagrid("getSelected");

    if (selRow == null) {

        $(_inputItemObj).val("");

        $(_inputItemObj).attr("ItemId", "");


    } else {

        $(_inputItemObj).val(selRow.ItemName);

        $(_inputItemObj).attr("ItemId", selRow.Id);

        if (_inputItemCallBack != null && _inputItemCallBack != undefined) {
            _inputItemCallBack();
        }

    }


    btnCancelItemClick();
}


function btnCancelItemClick() {
    layer.close(_winSelectItem);


}

//*************************************************************************************



Array.prototype.indexOf = function (val) {
    for (var i = 0; i < this.length; i++) {
        if (this[i] == val) return i;
    }
    return -1;
};

Array.prototype.remove = function (val) {
    var index = this.indexOf(val);
    if (index > -1) {
        this.splice(index, 1);
    }
};

//http//www.baidu.com/pub/item.aspx?t=7    获取  pub/item.aspx
function GetUrlRelativePath() {
    var url = document.location.toString();
    var arrUrl = url.split("//");

    var start = arrUrl[1].indexOf("/")+1;
    var realUrl = arrUrl[1].substring(start);

    if (realUrl.indexOf("?") != -1) {
        realUrl = realUrl.split("?")[0];
    }

    return realUrl;
}

//http//www.baidu.com/pub/item.aspx?t=7    获取  http//www.baidu.com/pub/item.aspx
function GetUrlMainPath() {
    var url = document.location.toString();

    if (url.indexOf("?") != -1) {
        url = url.split("?")[0];
    }
 
    return url;

}



//字符串格式化
var stringFormat = function () {
    if (arguments.length == 0)
        return null;
    var str = arguments[0];
    for (var i = 1; i < arguments.length; i++) {
        var re = new RegExp('\\{' + (i - 1) + '\\}', 'gm');
        str = str.replace(re, arguments[i]);
    }

    return str;
}

//显示分页
function showPage(pageHander, pageHanderName, pageRegionID, onChoosePage, isShowFloor, pageIndex, pageSize, pageCount, itemCount) {
    //初始化
    pageHander.PageNo = pageIndex;
    pageHander.PageSize = pageSize;
    pageHander.IsShowFloor = isShowFloor;

    //呈现
    pageHander.ShowPage(pageHanderName, pageRegionID, onChoosePage, itemCount);
}

//是否是IE浏览器
function isNavigatorIE() {
    if (!!window.ActiveXObject || "ActiveXObject" in window)
        return true;
    else
        return false;
}

//回车按键被按下并松开事件句柄
var enterKeyPress = function (e, clickCallback) {
    if (e.keyCode == 13) {
        clickCallback();
    }
}

var validateUtility = {
    isValidBaseString: function (stringText) {
        var result = true;

        var regPatternStr = "^[A-Za-z0-9 \u4E00-\u9FA5]+$";
        var regExp = new RegExp(regPatternStr);
        result = regExp.test(stringText)

        return result;
    }
}

//收藏本站
function AddFavorite(sURL, sTitle) {
    try {
        window.external.addFavorite(sURL, sTitle);
    }
    catch (e) {
        try {
            window.sidebar.addPanel(sTitle, sURL, "");
        }
        catch (e) {
            alert("请使用Ctrl+D进行添加!");
        }
    }

}


function GetSimpleArea(areaStr) {

    areaStr = areaStr.replace("省", "");

    var arrArea = areaStr.split("-");

    if (arrArea.length == 2) {

        return arrArea[0] + arrArea[1];

    } else if (arrArea.length == 3) {
        return arrArea[0] + arrArea[2];
    } else {
        return areaStr;
    }


}


function GetCurrentDomain()
{
    var domain = window.location.hostname.split('.').slice(1).join('.');

    return domain;
}

